package com.bw.module_message.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.bw.module_message.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.http.entity.MessageEntityItem

class MessageAdapter : BaseQuickAdapter<MessageEntityItem, BaseViewHolder>(
    R.layout.message_item
) {
    override fun convert(holder: BaseViewHolder, item: MessageEntityItem) {
        val cardView = holder.getView<CardView>(R.id.message_item_cv)
        cardView.radius = 15f
        val imageView = holder.getView<ImageView>(R.id.message_item_iv)
        when(item.messageType){
            "系统通知"->{
                imageView.setBackgroundResource(R.drawable.message_item_image_bg1)
                imageView.setImageResource(R.drawable.message_notice)
            }
            "物业服务"->{
                imageView.setBackgroundResource(R.drawable.message_item_image_bg2)
                imageView.setImageResource(R.drawable.message_setting)
            }
            "车位管理"->{
                imageView.setBackgroundResource(R.drawable.message_item_image_bg3)
                imageView.setImageResource(R.drawable.message_car)
            }
        }
        holder.setText(R.id.message_item_tv_title,item.messageType)
        holder.setText(R.id.message_item_tv_content,item.messageContent)
        holder.setText(R.id.message_item_tv_time,item.sendTime)
        val textView = holder.getView<TextView>(R.id.message_item_tv_status)
        when(item.messageStatus){
            "已读"->{
                textView.setBackgroundResource(R.drawable.message_item_tv_bg1)
                textView.text = item.messageStatus
            }
            "未读"->{
                textView.setBackgroundResource(R.drawable.message_item_tv_bg2)
                textView.text = item.messageStatus
            }

        }
    }
}